<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body {
            margin: 0; /*去掉外边距*/
            background-image: url("images/index/bg1.jpg");
            background-size: cover; /*设置封面*/
            text-align: center; /*页面内部的文本居中*/
        }

        h1 {
            font-size: 72px;
            color: #0096dc;
            margin-bottom: 0;
        }

        img {
            width: 80px;
        }

        h2 {
            font-size: 32px;
            color: #0096dc;
            margin-bottom: 0;
        }
        .tool {
            display: flex;
            justify-content: space-between;
            color: #606266;
        }
        .shou {
            cursor: pointer;
            /*color: #606266;*/
            color: #666;
            text-decoration: none;
        }

        .forgetPas {
            text-align: right;
            color: #b61d1d;
        }

        .loginBtn {
            border: 1px solid #e85356;
            display: block;
            width: 400px;
            background: #e4393c;
            height: 40px;
            line-height: 40px;
            color: #fff;
            font-size: 20px;
            margin-top: 20px;

        }
        .loginBtn:active {
            background-color: #e2231a;
        }
        .loginBtn:focus{
            background: #e2231a;
        }

    </style>
</head>
<body>
<div id="app">
    <h1>欢迎来到学霸商城</h1>
    <img src="images/index/p2.jpg" alt="">
    <h2 style="margin: 10px">SuperScholarMall</h2>
    <el-card style="width: 600px;height: 350px;margin: 0 auto;
                background-color:#FFFFFF;border: none">
        <!--label-width设置用户名这一列所占的宽度,如果不设置会显示在上面-->
        <el-form label-width="60px" style="width: 400px;margin: 50px auto">
            <el-form-item  label="用户名" >
                <el-input type="text" v-model="user.username" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="user.password" placeholder="请输入密码"></el-input>
            </el-form-item>
            <div class="tool">
                <div>
                    <el-checkbox v-model="user.rem" @change="remenber">记住密码</el-checkbox>
                </div>
                <div>
                    <span class="shou" @click="forgetpas">忘记密码</span>
                </div>
            </div>
            <div>
                <button class="loginBtn" @click="login()">登 录</button>
            </div>
<!--            <el-form-item style="margin-left: 0px;">-->
<!--                <el-button class="loginBtn"-->
<!--                           type="primary" @click="login()">登 录-->
<!--                </el-button>-->
<!--            </el-form-item>-->
            <el-form-item class="forgetPas" >
                <span @click="forgetpas">立即注册</span>
            </el-form-item>
        </el-form>
    </el-card>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user: {
                    username: "",
                    password: "",
                    rem:false,
                }
            }
        },
        methods: {
            login() {
                debugger
                axios.post("/login", v.user).then(function (response) {
                    if (response.data == 1) {
                        location.href = "/index.html";
                    } else if (response.data == 2) {
                        v.$message.error("用户名不存在!");
                    } else {
                        v.$message.error("密码错误!");
                    }
                })
            },
            remenber() {

            },
            forgetpas() {
                location.href = "forget.html";
            },
        },
        created:function () {
            let arr = document.cookie.split(";");
            for (let cookie of arr){
                let cookieArr = cookie.split("=");
                let name = cookieArr[0].trim();
                let value=cookieArr[1];
                if (name == "username"){
                    this.user.username= value;
                }else if( name == "password"){
                    this.user.password=value;
                }
            }
        }
    })
</script>
</html>